﻿namespace Sidvall.AuthorizationManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AuthorizationScope : global::Sidvall.AuthorizationManager.UI.Entities.Core.BusinessBase, global::Sidvall.AuthorizationManager.Data.IAuthorizationScope
    {
        #region Business Members

        #region AuthorizationScopeId

        private System.Nullable<long> _AuthorizationScopeId = null;
        partial void OnBeforeAuthorizationScopeIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData);
        partial void OnBeforeAuthorizationScopeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterAuthorizationScopeIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<long> AuthorizationScopeId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<long>>(_AuthorizationScopeId);
                OnBeforeAuthorizationScopeIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _AuthorizationScopeId);
                OnBeforeAuthorizationScopeIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("AuthorizationScopeId", eventData.Value, true, true, true);
                    OnAfterAuthorizationScopeIdPropertyChanged();
                }
            }
        }

        #endregion
        #region DefaultResourceActionAccessLevel

        private global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel _DefaultResourceActionAccessLevel = global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel.Public;
        partial void OnBeforeDefaultResourceActionAccessLevelPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel> eventData);
        partial void OnBeforeDefaultResourceActionAccessLevelPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel> eventData);
        partial void OnAfterDefaultResourceActionAccessLevelPropertyChanged();
        public global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel DefaultResourceActionAccessLevel
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel>(_DefaultResourceActionAccessLevel);
                OnBeforeDefaultResourceActionAccessLevelPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel>(value, _DefaultResourceActionAccessLevel);
                OnBeforeDefaultResourceActionAccessLevelPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("DefaultResourceActionAccessLevel", eventData.Value, true, true, true);
                    OnAfterDefaultResourceActionAccessLevelPropertyChanged();
                }
            }
        }

        #endregion
        #region DefaultResourceItemAccessLevel

        private global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel _DefaultResourceItemAccessLevel = global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel.Public;
        partial void OnBeforeDefaultResourceItemAccessLevelPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel> eventData);
        partial void OnBeforeDefaultResourceItemAccessLevelPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel> eventData);
        partial void OnAfterDefaultResourceItemAccessLevelPropertyChanged();
        public global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel DefaultResourceItemAccessLevel
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel>(_DefaultResourceItemAccessLevel);
                OnBeforeDefaultResourceItemAccessLevelPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel>(value, _DefaultResourceItemAccessLevel);
                OnBeforeDefaultResourceItemAccessLevelPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("DefaultResourceItemAccessLevel", eventData.Value, true, true, true);
                    OnAfterDefaultResourceItemAccessLevelPropertyChanged();
                }
            }
        }

        #endregion
        #region DefaultUserContext

        private string _DefaultUserContext = string.Empty;
        partial void OnBeforeDefaultUserContextPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeDefaultUserContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterDefaultUserContextPropertyChanged();
        public string DefaultUserContext
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_DefaultUserContext);
                OnBeforeDefaultUserContextPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _DefaultUserContext);
                OnBeforeDefaultUserContextPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("DefaultUserContext", eventData.Value, true, true, true);
                    OnAfterDefaultUserContextPropertyChanged();
                }
            }
        }

        #endregion
        #region IsEnabled

        private bool _IsEnabled = false;
        partial void OnBeforeIsEnabledPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeIsEnabledPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledPropertyChanged();
        public bool IsEnabled
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IsEnabled);
                OnBeforeIsEnabledPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabled);
                OnBeforeIsEnabledPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IsEnabled", eventData.Value, true, true, true);
                    OnAfterIsEnabledPropertyChanged();
                }
            }
        }

        #endregion
        #region MissingUserPolicyId

        private global::Sidvall.AuthorizationManager.Data.MissingUserPolicy _MissingUserPolicyId = global::Sidvall.AuthorizationManager.Data.MissingUserPolicy.None;
        partial void OnBeforeMissingUserPolicyIdPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.MissingUserPolicy> eventData);
        partial void OnBeforeMissingUserPolicyIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.MissingUserPolicy> eventData);
        partial void OnAfterMissingUserPolicyIdPropertyChanged();
        public global::Sidvall.AuthorizationManager.Data.MissingUserPolicy MissingUserPolicyId
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.MissingUserPolicy> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.MissingUserPolicy>(_MissingUserPolicyId);
                OnBeforeMissingUserPolicyIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.MissingUserPolicy> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.MissingUserPolicy>(value, _MissingUserPolicyId);
                OnBeforeMissingUserPolicyIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("MissingUserPolicyId", eventData.Value, true, true, true);
                    OnAfterMissingUserPolicyIdPropertyChanged();
                }
            }
        }

        #endregion
        #region Name

        private string _Name = string.Empty;
        partial void OnBeforeNamePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Name);
                OnBeforeNamePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                OnBeforeNamePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Name", eventData.Value, true, true, true);
                    OnAfterNamePropertyChanged();
                }
            }
        }

        #endregion
        #region RequireActiveUser

        private bool _RequireActiveUser = false;
        partial void OnBeforeRequireActiveUserPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeRequireActiveUserPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterRequireActiveUserPropertyChanged();
        public bool RequireActiveUser
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_RequireActiveUser);
                OnBeforeRequireActiveUserPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _RequireActiveUser);
                OnBeforeRequireActiveUserPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("RequireActiveUser", eventData.Value, true, true, true);
                    OnAfterRequireActiveUserPropertyChanged();
                }
            }
        }

        #endregion
        #region ResourceItemPolicyId

        private global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy _ResourceItemPolicyId = global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy.UseItemsAndActionsWithFilter;
        partial void OnBeforeResourceItemPolicyIdPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy> eventData);
        partial void OnBeforeResourceItemPolicyIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy> eventData);
        partial void OnAfterResourceItemPolicyIdPropertyChanged();
        public global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy ResourceItemPolicyId
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy>(_ResourceItemPolicyId);
                OnBeforeResourceItemPolicyIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy>(value, _ResourceItemPolicyId);
                OnBeforeResourceItemPolicyIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ResourceItemPolicyId", eventData.Value, true, true, true);
                    OnAfterResourceItemPolicyIdPropertyChanged();
                }
            }
        }

        #endregion
        #region ServerConnectionId

        private System.Nullable<System.Int32> _ServerConnectionId = null;
        partial void OnBeforeServerConnectionIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.Int32>> eventData);
        partial void OnBeforeServerConnectionIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>> eventData);
        partial void OnAfterServerConnectionIdPropertyChanged();
        public System.Nullable<System.Int32> ServerConnectionId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.Int32>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.Int32>>(_ServerConnectionId);
                OnBeforeServerConnectionIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>>(value, _ServerConnectionId);
                OnBeforeServerConnectionIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ServerConnectionId", eventData.Value, true, true, true);
                    OnAfterServerConnectionIdPropertyChanged();
                }
            }
        }

        #endregion
        #region AuthorizationScopeExports

        private AuthorizationScopeExportCollection _AuthorizationScopeExports;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public AuthorizationScopeExportCollection AuthorizationScopeExports
        {
            get
            {
                return _AuthorizationScopeExports;
            }
            internal set
            {
                LoadInstanceField("AuthorizationScopeExports", value, true, false, false);
            }
        }

        #endregion
        #region AuthorizationScopeResourceActions

        private AuthorizationScopeResourceActionCollection _AuthorizationScopeResourceActions;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public AuthorizationScopeResourceActionCollection AuthorizationScopeResourceActions
        {
            get
            {
                return _AuthorizationScopeResourceActions;
            }
            internal set
            {
                LoadInstanceField("AuthorizationScopeResourceActions", value, true, false, false);
            }
        }

        #endregion
        #region AuthorizationScopeResourceItems

        private AuthorizationScopeResourceItemCollection _AuthorizationScopeResourceItems;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public AuthorizationScopeResourceItemCollection AuthorizationScopeResourceItems
        {
            get
            {
                return _AuthorizationScopeResourceItems;
            }
            internal set
            {
                LoadInstanceField("AuthorizationScopeResourceItems", value, true, false, false);
            }
        }

        #endregion
        #region AuthorizationScopeUsers

        private AuthorizationScopeUserCollection _AuthorizationScopeUsers;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public AuthorizationScopeUserCollection AuthorizationScopeUsers
        {
            get
            {
                return _AuthorizationScopeUsers;
            }
            internal set
            {
                LoadInstanceField("AuthorizationScopeUsers", value, true, false, false);
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadAuthorizationScopeExports

        public void LoadAuthorizationScopeExports(AuthorizationScopeExportCollection value)
        {
            LoadInstanceField("AuthorizationScopeExports", value, true, true, false);
        }

        #endregion
        #region LoadAuthorizationScopeResourceActions

        public void LoadAuthorizationScopeResourceActions(AuthorizationScopeResourceActionCollection value)
        {
            LoadInstanceField("AuthorizationScopeResourceActions", value, true, true, false);
        }

        #endregion
        #region LoadAuthorizationScopeResourceItems

        public void LoadAuthorizationScopeResourceItems(AuthorizationScopeResourceItemCollection value)
        {
            LoadInstanceField("AuthorizationScopeResourceItems", value, true, true, false);
        }

        #endregion
        #region LoadAuthorizationScopeUsers

        public void LoadAuthorizationScopeUsers(AuthorizationScopeUserCollection value)
        {
            LoadInstanceField("AuthorizationScopeUsers", value, true, true, false);
        }

        #endregion
        #region LoadAuthorizationScopeExportsAsync

        public async System.Threading.Tasks.Task<AuthorizationScopeExportCollection> LoadAuthorizationScopeExportsAsync()
        {
            return await LoadAuthorizationScopeExportsAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeExportCollection> LoadAuthorizationScopeExportsAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeExportRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeManager.LoadAuthorizationScopeExportsAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.AuthorizationScopeExports;
        }

        #endregion
        #region LoadAuthorizationScopeResourceActionsAsync

        public async System.Threading.Tasks.Task<AuthorizationScopeResourceActionCollection> LoadAuthorizationScopeResourceActionsAsync()
        {
            return await LoadAuthorizationScopeResourceActionsAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeResourceActionCollection> LoadAuthorizationScopeResourceActionsAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeManager.LoadAuthorizationScopeResourceActionsAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.AuthorizationScopeResourceActions;
        }

        #endregion
        #region LoadAuthorizationScopeResourceItemsAsync

        public async System.Threading.Tasks.Task<AuthorizationScopeResourceItemCollection> LoadAuthorizationScopeResourceItemsAsync()
        {
            return await LoadAuthorizationScopeResourceItemsAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeResourceItemCollection> LoadAuthorizationScopeResourceItemsAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceItemField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceItemRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeManager.LoadAuthorizationScopeResourceItemsAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.AuthorizationScopeResourceItems;
        }

        #endregion
        #region LoadAuthorizationScopeUsersAsync

        public async System.Threading.Tasks.Task<AuthorizationScopeUserCollection> LoadAuthorizationScopeUsersAsync()
        {
            return await LoadAuthorizationScopeUsersAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeUserCollection> LoadAuthorizationScopeUsersAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeUserField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeUserRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeManager.LoadAuthorizationScopeUsersAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.AuthorizationScopeUsers;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public AuthorizationScope Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public AuthorizationScope Copy()
        {
            return Copy(null);
        }
        public AuthorizationScope Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new AuthorizationScope();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScope item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScope item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(AuthorizationScope destination, global::Sidvall.AuthorizationManager.Data.IAuthorizationScope source, Sidvall.Data.CopySettings copySettings);
        private void Import(AuthorizationScope destination, global::Sidvall.AuthorizationManager.Data.IAuthorizationScope source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(AuthorizationScope destination, AuthorizationScope source, Sidvall.Data.CopySettings copySettings);
        private void Import(AuthorizationScope destination, AuthorizationScope source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.AuthorizationManager.Data.IAuthorizationScope, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AuthorizationScope> SaveItemAsync()
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeManager.SaveItemAsync(this);
        }
        public async System.Threading.Tasks.Task<AuthorizationScope> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeManager.SaveItemAsync(this, mode);
        }
        public async System.Threading.Tasks.Task<AuthorizationScope> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeManager.SaveItemAsync(this, settings);
        }
        public async System.Threading.Tasks.Task<AuthorizationScope> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeManager.SaveItemAsync(this, settings, strategyContext, objectParameters);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeManager.Initialize(this, settings);
        }

        #endregion
        
        #region IAuthorizationScope Members

        System.Nullable<long> global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.AuthorizationScopeId
        {
            get
            {
                return this._AuthorizationScopeId;
            }
            set
            {
                this._AuthorizationScopeId = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.DefaultResourceActionAccessLevel
        {
            get
            {
                return this._DefaultResourceActionAccessLevel;
            }
            set
            {
                this._DefaultResourceActionAccessLevel = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.AuthorizationScopeAccessLevel global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.DefaultResourceItemAccessLevel
        {
            get
            {
                return this._DefaultResourceItemAccessLevel;
            }
            set
            {
                this._DefaultResourceItemAccessLevel = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.DefaultUserContext
        {
            get
            {
                return this._DefaultUserContext;
            }
            set
            {
                this._DefaultUserContext = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.IsEnabled
        {
            get
            {
                return this._IsEnabled;
            }
            set
            {
                this._IsEnabled = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.MissingUserPolicy global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.MissingUserPolicyId
        {
            get
            {
                return this._MissingUserPolicyId;
            }
            set
            {
                this._MissingUserPolicyId = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.RequireActiveUser
        {
            get
            {
                return this._RequireActiveUser;
            }
            set
            {
                this._RequireActiveUser = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.ResourceItemActionPolicy global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.ResourceItemPolicyId
        {
            get
            {
                return this._ResourceItemPolicyId;
            }
            set
            {
                this._ResourceItemPolicyId = value;
            }
        }
        System.Nullable<System.Int32> global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.ServerConnectionId
        {
            get
            {
                return this._ServerConnectionId;
            }
            set
            {
                this._ServerConnectionId = value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport> global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.AuthorizationScopeExports
        {
            get
            {
                return this._AuthorizationScopeExports;
            }
        }
        void global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.SetAuthorizationScopeExports(Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport> items)
        {
            UpdateChildProperty(this._AuthorizationScopeExports, items);
            this._AuthorizationScopeExports = items as AuthorizationScopeExportCollection;
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction> global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.AuthorizationScopeResourceActions
        {
            get
            {
                return this._AuthorizationScopeResourceActions;
            }
        }
        void global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.SetAuthorizationScopeResourceActions(Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction> items)
        {
            UpdateChildProperty(this._AuthorizationScopeResourceActions, items);
            this._AuthorizationScopeResourceActions = items as AuthorizationScopeResourceActionCollection;
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem> global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.AuthorizationScopeResourceItems
        {
            get
            {
                return this._AuthorizationScopeResourceItems;
            }
        }
        void global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.SetAuthorizationScopeResourceItems(Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem> items)
        {
            UpdateChildProperty(this._AuthorizationScopeResourceItems, items);
            this._AuthorizationScopeResourceItems = items as AuthorizationScopeResourceItemCollection;
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser> global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.AuthorizationScopeUsers
        {
            get
            {
                return this._AuthorizationScopeUsers;
            }
        }
        void global::Sidvall.AuthorizationManager.Data.IAuthorizationScope.SetAuthorizationScopeUsers(Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser> items)
        {
            UpdateChildProperty(this._AuthorizationScopeUsers, items);
            this._AuthorizationScopeUsers = items as AuthorizationScopeUserCollection;
        }

        #endregion

        #endregion
        #region Constructors

        public AuthorizationScope()
        {
        }

        public AuthorizationScope(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}